<template>
    <div class="ma-content-block lg:flex justify-between p-4">
      <!-- CRUD 组件 -->
      <ma-crud :options="options" :columns="columns" ref="crudRef">
        <template #pay_type="{ record }">
            <div>{{ record?.pay_order.pay_type == 'money'?'预付款':record?.pay_order.pay_type=='periodic'?'周期结算':'现结' }}</div>
        </template>
        <template #now_pay_type="{ record }">
            <div>{{ record?.pay_order.now_pay_type=='1'?'惠支付':record?.pay_order.now_pay_type=='2'?'现金':record?.pay_order.now_pay_type=='3'?'对公转账':'' }}</div>
        </template>
      </ma-crud>
    </div>
  </template>
  <script setup>
  import { ref, reactive } from 'vue'
  import financialReportexcel from '@/api/financial/financialReportexcel'
  import { Message } from '@arco-design/web-vue'
  import tool from '@/utils/tool'
  import * as common from '@/utils/common'
  
  const crudRef = ref()
  const tablecolumnsts = [
      {
        title: '收费项目',
        dataIndex: 'item_name',

      },
      {
        title: '金额',
        dataIndex: 'pay_price',
      },
];
  
  const numberOperation = (newValue, id, numberName) => {
    financialReportexcel.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
      res.success && Message.success(res.message)
    }).catch( e => { console.log(e) } )
  }
  
  const switchStatus = (statusValue, id, statusName) => {
    financialReportexcel.changeStatus({ id, statusName, statusValue }).then( res => {
      res.success && Message.success(res.message)
    }).catch( e => { console.log(e) } )
  }
  
  
  const options = reactive({
    id: 'financial_unloading',
    rowSelection: {
      showCheckedAll: true
    },
    pk: 'id',
    operationColumn: false,
    api: financialReportexcel.payOrderDetail,
    export: {
      show: true,
      url: 'financial/payOrderDetail/export',
      auth: ['financial:payOrderDetail:export']
    },
    beforeRequest: (paramse) => {
        paramse.jiesuan_report = "2";
    },
    afterRequest: (params) => {
        params.map((v, i) => {
            v.pay_type = v.pay_order.pay_type
            v.now_pay_type = v.pay_order.now_pay_type
            if(v.pay_order){
                let arr = []
                let arrs = []
                v.pay_order.pay_items_json.map((vv,ii)=>{
                    if(vv.pay_price != '0.00'){
                        arr.push(vv)
                    }
                })
                for(let i = 0;i<arr.length;i++){
                    let num = arrs.findIndex(item=>{
                        return item.item_name == arr[i].item_name
                    })
                    if(num == -1){
                        arrs.push(arr[i])
                    }else{
                        arrs[num].pay_price = ((arr[i].pay_price - 0) + (arrs[num].pay_price - 0)).toFixed(2)
                    }
                }
                v.pay_order.pay_items_json = arrs
                
            }
        });
        
    },
  })
  
  const columns = reactive([
    {
      title: "ID",
      dataIndex: "id",
      formType: "input",
      addDisplay: false,
      editDisplay: false,
      hide: true,
      commonRules: {
        required: true,
        message: "请输入ID"
      }
    },
    {
      title: "装车单号",
      dataIndex: "pay_order.driver_order.order_no",
      formType: "input",
      width:180,
      align:'center'
    },
    {
      title: "公司名称",
      dataIndex: "pay_order.dept.name",
      formType: "input",
      width:180,
      align:'center'
    },
    {
      title: "交易单号",
      dataIndex: "pay_order.order_number",
      formType: "input",
      width:180,
      align:'center'
      
    },
    {
      title: "费用名称",
      dataIndex: "pay_name",
      formType: "input",
      width:180,
      align:'center'
    },
    {
      title: "交易金额",
      dataIndex: "pay_price",
      formType: "input",
      width:180,
      align:'center'
    },
    {
      title: "支付方式",
      dataIndex: "pay_type",
      formType: "input",
      width:180,
      align:'center'
    },
    {
      title: "现结支付类型",
      dataIndex: "now_pay_type",
      formType: "input",
      width:180,
      align:'center'
    },
    {
      title: "关联订单",
      dataIndex: "pay_order.prediction_order_number",
      formType: "input",
      width:180,
      align:'center'
    },
    {
      title: "交易时间",
      dataIndex: "pay_order.pay_date",
      formType: "range",
      addDisplay: false,
      editDisplay: false,
      showTime: true,
      width:180,
      align:'center'
    },
  ])
  </script>
  <script> export default { name: 'financial:delivery' } </script>